package com.liaoyifan.core.enums;

import java.util.Arrays;
import java.util.function.Function;
import java.util.stream.Collectors;

@SuppressWarnings("unused")
public interface ICodeEnum {

    int getCode();

    String getMessage();

    @SuppressWarnings("ResultOfMethodCallIgnored")
    static void unique(ICodeEnum[] values) {
        Arrays.stream(values)
                .collect(
                        Collectors.toMap(
                                ICodeEnum::getCode,
                                Function.identity(),
                                (e1, e2) -> {
                                    throw new IllegalStateException("REPEAT CODE: " + e1.getCode());
                                }));
    }
}
